<?php
function create_contact_table()
{
	global $wpdb;

	$search_table = $wpdb->prefix . "contact";

	//check if there are any tables of that name already
	if ($wpdb->get_var("show tables like '$search_table'") !== $search_table)
	{
		//create your sql
		$sql = "
        CREATE TABLE {$search_table} (
        contact_id MEDIUMINT (12) NOT NULL AUTO_INCREMENT,
        name VARCHAR (20) NOT NULL,
        email VARCHAR (50) NOT NULL,
        subject TEXT NOT NULL,
        issue text NOT NULL,
        message LONGTEXT NOT NULL,
        TIME DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
        UNIQUE KEY contact_id (contact_id)
        );
        ";
	}

	//include the wordpress db functions
	require_once (ABSPATH . 'wp-admin/upgrade-functions.php');
	dbDelta($sql);

	//register the new table with the wpdb object
	if (!isset($wpdb->follow))
	{
		$wpdb->follow = $search_table;
		$wpdb->tables[] = str_replace($wpdb->prefix, '', $search_table);
	}
}
//add to front and backend inits
        add_action('init', 'create_contact_table');
?>
